#include "Polygone.h"
#include <iostream>

namespace sffs {

// Constructor()
Polygone::Polygone()
{
	m_Shape.AddPoint(0.0f, 0.0f, m_Color, sf::Color(0,0,0)) ;
	m_Shape.AddPoint(0.0f, 0.0f, m_Color, sf::Color(0,0,0)) ;
	m_Shape.AddPoint(0.0f, 0.0f, m_Color, sf::Color(0,0,0)) ;
	m_Shape.EnableFill(true) ;
	m_Shape.SetColor(m_Color) ;
	m_Shape.EnableOutline(true) ;
	m_Shape.SetOutlineWidth(0.0f) ;
}

// Constructor(pair<float,float>, pair<float,float>, pair<float,float>, sf::Color)
Polygone::Polygone(const std::vector<std::pair<float, float>>& _cornerVector, const sf::Color& _Color)
	: m_Color(_Color)
{
	for(int i=0;i< _cornerVector.size();i++)
	{
		m_Shape.AddPoint(_cornerVector[i].first, _cornerVector[i].second, _Color, sf::Color(0,0,0));
	}
	m_Shape.EnableFill(true) ;
	m_Shape.SetColor(m_Color) ;
	m_Shape.EnableOutline(true) ;
	m_Shape.SetOutlineWidth(0.0f) ;
	oldTime =0;
}

Polygone::Polygone(const std::vector<std::pair<float, float>>& _cornerVector, const std::vector<sf::Color>& _ColorVector )
	: m_ColorVector(_ColorVector)
{
	for(int i=0;i< _cornerVector.size();i++)
	{
		m_Shape.AddPoint(_cornerVector[i].first, _cornerVector[i].second, _ColorVector[0],  _ColorVector[0]);
	}
	m_Color=m_ColorVector[0];
	m_Shape.EnableFill(true) ;
	m_Shape.SetColor(m_Color) ;
	m_Shape.EnableOutline(true) ;
	m_Shape.SetOutlineWidth(0.0f) ;
	oldTime =0;
	currentColorRank =0;
}

// Destructor
Polygone::~Polygone()
{
}

// SetColor
void Polygone::SetColor(int _R, int _G, int _B)
{
	m_Color = m_ColorVector[0] ;
	m_Shape.SetColor(m_Color) ;
	m_Shape.SetPointColor(0, m_Color) ;
	m_Shape.SetPointColor(1, m_Color) ;
	m_Shape.SetPointColor(2, m_Color) ;
}

// Draw
void Polygone::Draw() const
{
	Polygone::m_Window->Draw(m_Shape) ;
}

// ChangeColor
void Polygone::ChangeColor(int newTime)
{
	if(newTime-oldTime>500)
	{
		currentColorRank = ((currentColorRank+1)%m_ColorVector.size());
		std::cout<<" Couleur avant polygone : "<<currentColorRank<<
			" / "<<(int) m_ColorVector[currentColorRank].r<<
			" / "<<(int) m_ColorVector[currentColorRank].g<<
			" / "<<(int) m_ColorVector[currentColorRank].b<<std::endl;
		m_Color = m_ColorVector[currentColorRank];
		m_Shape.EnableFill(true) ;
		m_Shape.SetColor(m_Color) ;
		sf::Color color = m_Shape.GetColor();
		std::cout<<" Couleur dans le polygone : "<<currentColorRank<<
			" / "<<(int) color.r<<
			" / "<<(int) color.g<<
			" / "<<(int) color.b<<std::endl;

		oldTime = newTime;
	}
}

} // namespace sffs
